﻿using System;
using System.IO;
using System.Text;
using System.Web;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Test
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            string base64String = null;
            string path = "G:\\image\\";
            using (FileStream fs = new FileStream(@"G:\\image\\test.png", FileMode.Open))
            {
                int fsLen = (int)fs.Length;
                byte[] heByte = new byte[fsLen];
                int r = fs.Read(heByte, 0, heByte.Length);
                base64String = HttpUtility.UrlEncode(Convert.ToBase64String(heByte), Encoding.UTF8);
              
            }

            byte[] arr = Convert.FromBase64String(base64String);
            string imageName = path + Guid.NewGuid().ToString() + ".jpg";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            using (FileStream fs = new FileStream(imageName, FileMode.Create))
            {
                fs.Write(arr, 0, arr.Length);
                fs.Flush();
                fs.Close();
            }
        }
    }
}
